<?php
// no direct access
defined('_JEXEC') or die('Restricted access');

// import application controller
jimport('joomla.application.component.controller');

class SyncrControllerHolding extends JController
{
	public function __construct($config = array()) {
		parent::__construct($config);
	}
	
	public function display()
	{
		// set view if not specified
		if (!$view = JRequest::getVar('view')) {
			JRequest::setVar('view', 'holding');
		}
		
		// call parent behavior
		parent::display();
	}
	
	public function publish()
	{	
		if (!JRequest::checkToken('REQUEST')) {
			JError::raiseError(403, JText::_('ALERTNOAUTH'));
			jexit('Invalid token');
		}
		
		$cid = JRequest::getVar('cid', array(0), 'post', 'array');

		$model =& $this->getModel('publish');
		$published = $model->publish();
		
		if ($published == true) {
			if (count($cid) > 1) {
				$msg = JText::_('SELECTED_ITEMS_HAVE_BEEN_PUBLISHED');
			} else {
				$msg = JText::_('SELECTED_ITEM_HAS_BEEN_PUBLISHED');
			}
		} else {
			$msg = $published;
		}
						
		$this->setRedirect('?option=com_syncr&controller=holding', $msg);
	}
	
	public function remove()
	{
		if (!JRequest::checkToken('REQUEST')) {
			JError::raiseError(403, JText::_('ALERTNOAUTH'));
			jexit('Invalid token');
		}
		
		$cid = JRequest::getVar('cid', array());
		$row =& JTable::getInstance('hold', 'Table');
		
		foreach ($cid as $id)
		{	
			$id = (int) $id;
			if (!$row->delete($id)) {
				JError::raiseError(500, $row->getError());
			}
		}
		
		if (count($cid) > 1) {
			$msg = JText::_('SELECTED_ITEMS_HAVE_BEEN_DELETED');
		} else {
			$msg = JText::_('SELECTED_ITEM_HAS_BEEN_DELETED');
		}
		
		$this->setRedirect('?option=com_syncr&controller=holding', $msg);
	}
}